﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Controls.Maps;
using System.Device.Location;
using HCMServices.DTO;

namespace HCMServices.GUI
{
    /// <summary>
    /// Details of place page. Place is chosen one in result searching list.
    /// </summary>
    public partial class PlaceDetailsPage : PhoneApplicationPage
    {
        /// <summary>
        /// Initialize All Component in this function
        /// </summary>
        public PlaceDetailsPage()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Container content all infomation about service that will be show on.
        /// </summary>
        public GUI.Service Service { get; set; }
        public DataDTO Data { get; set; }

        private List<DetailServiceDTO> _listDeltailService = new List<DetailServiceDTO>();

        public List<DetailServiceDTO> ListDeltailService
        {
            get { return _listDeltailService; }
            set { _listDeltailService = value; }
        }

        private bool _isSearchingNearby = false;

        public bool IsSearchingNearby
        {
            get { return _isSearchingNearby; }
            set { _isSearchingNearby = value; }
        }
        

        private void ContentPanel_Loaded(object sender, RoutedEventArgs e)
        {   


        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            //////Show + - Button for zoom in/out map
            //this.map.ZoomBarVisibility = Visibility.Visible;

            //////Show Pushpin for place
            /////  
            //Pushpin pushpin = new Pushpin();
            //pushpin.Location = new GeoCoordinate(Service.Data.Latitude, Service.Data.Longitude);
            //pushpin.Content = Service.Data.PlaceName;

            //map.Children.Add(pushpin);
            //map.SetView(pushpin.Location, 15);
            infoPanel.DataContext = Service;
        }

        private void buttonViewMap_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/GUI/MapView.xaml", UriKind.Relative));
        }

        private void buttonFindAround_Click(object sender, RoutedEventArgs e)
        {
            IsSearchingNearby = true;
            this.NavigationService.Navigate(new Uri("/GUI/MainPage.xaml", UriKind.Relative));
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            if (e.Content is GUI.MapView)
            {
                GUI.MapView mapViewInstance = e.Content as GUI.MapView;
                if (mapViewInstance != null)
                {
                    mapViewInstance.Service = Service;
                }
            }
            else if (e.Content is MainPage)
            {
                MainPage mainPageInstance = e.Content as MainPage;

                if (mainPageInstance != null)
                {
                    if (IsSearchingNearby)
                    {
                        mainPageInstance.EnableSearchNearbyPlace = true;
                        mainPageInstance.PassingData = Data;
                        IsSearchingNearby = false;
                    }                    
                }
            }            
        }
        public class test
        {
            public string Name { get; set; }
            public string Cost { get; set; }
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            List<test> a = new List<test>();            
            for (int i = 0; i < ListDeltailService.Count; i++ )
            {
                test c = new test();
                c.Name = ListDeltailService[i].Name;
                c.Cost = ListDeltailService[i].Cost.ToString();
                a.Add(c);
            }
            this.listBox1.ItemsSource = a;
        }
    }
}